﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using mmoss.classes.Interfaces;

namespace mmoss.classes
{
    public class DriversLicense : IScannedCard 
    {
        public string USBScanString { get; set; }
        public string FirstName { get; set; }
        public string MiddleName { get; set; }
        public string LastName { get; set; }
        public string CardNumber { get; set; }
        public DateTime ExpDate { get; set; }
        public string Address { get; set; }
        public string City { get; set; }
        public string ParseError { get; set; }
        public DateTime DOB { get; set; }
        public DriversLicense()
        {
        }
        public DriversLicense(string sCardString)
        {
            try
            {
                sCardString = sCardString.Replace("%CO", string.Empty);
                string sFirstPart = sCardString.Split('?')[0];
                string sSecondPart = sCardString.Split('?')[1];
                City = sFirstPart.Split('^')[0];
                LastName = sFirstPart.Split('^')[1].Split('$')[0];
                FirstName = sFirstPart.Split('^')[1].Split('$')[1];
                Address = sFirstPart.Split('^')[2];
                CardNumber = sSecondPart.Split('=')[0].Substring((sSecondPart.Split('=')[0]).Length  - 10, 10);
                string sDate=sSecondPart.Split('=')[1].Substring(0,4);
                string sDOB = sSecondPart.Split('=')[1].Substring(4, 8);
                DOB = DateTime.Parse(string.Format("{0}/{1}/{2}", sDOB.Substring(4, 2), sDOB.Substring(6, 2), sDOB.Substring(0, 4)));
                ExpDate = DateTime.Parse(string.Format("{0}/{1}/{2}", DOB.Month,DOB.Day,sDate.Substring(0, 2)));
            }
            catch (Exception ex)
            {
                ParseError = ex.Message;
            }
        }
    }
}
